home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / analyzer.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  7KB  |  356 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "ana.h"
  17. #include "ana_glob.h"
  18.  
  19.  
  20. private    int    numAdded;
  21.  
  22.  
  23. public char *SetName( n )
  24.   register char  *n;
  25.   {
  26.     int   i;
  27.  
  28.     i = strlen( n );
  29.     if( i > max_name_len )
  30.       {
  31.     i -= max_name_len;
  32.     n += i;
  33.       }
  34.     return( n );
  35.   }
  36.  
  37.  
  38. private void AddTrace( t )
  39.   Trptr  t;
  40.   {
  41.     if( traces.first == NULL )
  42.       {
  43.     t->next = t->prev = NULL;
  44.     traces.first = traces.last = t;
  45.       }
  46.     else
  47.       {
  48.     t->next = NULL;
  49.     t->prev = traces.last;
  50.     traces.last->next = t;
  51.     traces.last = t;
  52.       }
  53.     numAdded++;
  54.   }
  55.  
  56.  
  57. public int AddNode( nd, flag )
  58.   nptr  nd;
  59.   int   *flag;
  60.   {
  61.     Trptr  t;
  62.     
  63.     while( nd->nflags & ALIAS )
  64.     nd = nd->nlink;
  65.  
  66.     if( nd->nflags & MERGED )
  67.       {
  68.     fprintf( stderr, "can't watch node %s\n", nd->nname );
  69.     return( 1 );
  70.       }
  71.     if( (t = (Trptr) Valloc( sizeof( TraceEnt ), 0 )) == NULL )
  72.       {
  73.     fprintf( stderr, "Out of memory, can't add %s to analyzer\n",
  74.       nd->nname );
  75.     return( 0 );
  76.       }
  77.     t->name = SetName( nd->nname );
  78.     t->len = strlen( t->name );
  79.     t->bdigit = 1;
  80.     t->vector = FALSE;
  81.     t->n.nd = nd;
  82.     t->cache[0].wind = t->cache[0].cursor = &(nd->head);
  83.     AddTrace( t );
  84.     return( 1 );
  85.   }
  86.  
  87.  
  88. public int AddVector( vec, flag )
  89.   bptr  vec;
  90.   int   *flag;
  91.   {
  92.     Trptr  t;
  93.     int    n;
  94.  
  95.     n = vec->nbits;
  96.     t = (Trptr) Valloc( sizeof( TraceEnt ) + sizeof( Cache ) * (n - 1), 0 );
  97.     if( t == NULL )
  98.       {
  99.     fprintf( stderr, "Out of memory, can't add %s to analyzer\n",
  100.       vec->name );
  101.     return( 0 );
  102.       }
  103.     t->name = SetName( vec->name );
  104.     t->len = strlen( t->name );
  105.     if( *flag != 0 )
  106.     t->bdigit = *flag;
  107.     else
  108.     t->bdigit = ( n > 4 ) ? 4 : 1;
  109.     t->vector = TRUE;
  110.     t->n.vec = vec;
  111.     for( n--; n >= 0; n-- )
  112.     t->cache[n].wind = t->cache[n].cursor = &(vec->nodes[n]->head);
  113.     AddTrace( t );
  114.     return( 1 );
  115.   }
  116.  
  117.  
  118.  
  119. public void DisplayTraces( isMapped )
  120.   int  isMapped;
  121.   {
  122.     int  change;
  123.  
  124.     DisableInput();
  125.    
  126.     traces.total += numAdded;
  127.     numAdded = 0;
  128.  
  129.     if( not isMapped )                /* only the first time */
  130.       {
  131.     FlushTraceCache();
  132.     XMapWindow( display, window );
  133.       }
  134.     else if( not (windowState.iconified or windowState.tooSmall) )
  135.       {
  136.     change = WindowChanges();
  137.  
  138.     if( change & NTRACE_CHANGE )
  139.       {
  140.         RedrawNames( namesBox );
  141.         DrawCursVal( cursorBox );
  142.         if( change & WIDTH_CHANGE )
  143.           {
  144.         DrawScrollBar( FALSE );
  145.         RedrawTimes();
  146.           }
  147.         DrawTraces( tims.start, tims.end );
  148.       }
  149.       }
  150.  
  151.     EnableInput();
  152.   }
  153.  
  154.  
  155. public void StopAnalyzer()
  156.   {
  157.     DisableAnalyzer();
  158.   }
  159.  
  160.  
  161. public void RestartAnalyzer( first_time, last_time, same_hist )
  162.   long  first_time, last_time;
  163.   int   same_hist;
  164.   {
  165.     register Trptr  t;
  166.     register int    i, n;
  167.  
  168.     for( t = traces.first, i = traces.total; i != 0; i--, t = t->next )
  169.       {
  170.     if( t->vector )
  171.       {
  172.         for( n = t->n.vec->nbits - 1; n >= 0; n-- )
  173.           {
  174.         t->cache[n].wind = t->cache[n].cursor = 
  175.           &(t->n.vec->nodes[n]->head);
  176.           }
  177.       }
  178.     else
  179.         t->cache[0].wind = t->cache[0].cursor = &(t->n.nd->head);
  180.       }
  181.  
  182.     InitTimes( first_time, tims.steps / DEF_STEPS, last_time );
  183.     if( same_hist )
  184.     UpdateTraceCache( 0 );
  185.     else
  186.     FlushTraceCache();
  187.     EnableAnalyzer( /* same_hist */ );
  188.   }
  189.  
  190.  
  191. private void RemoveTrace( t )
  192.   Trptr  t;
  193.   {
  194.     traces.total--;
  195.     if( t == traces.first )
  196.       {
  197.     traces.first = t->next;
  198.     if( t->next )
  199.             t->next->prev = NULL;
  200.         else
  201.             traces.last = NULL;
  202.       }
  203.     else
  204.       {
  205.         t->prev->next = t->next;
  206.         if( t->next )
  207.             t->next->prev = t->prev;
  208.         else
  209.             traces.last = t->prev;
  210.       }
  211.     
  212.     if( selectedTrace == t )
  213.         selectedTrace = NULL;
  214.     Vfree( t );
  215.   }
  216.  
  217.  
  218. public void ClearTraces()
  219.   {
  220.     int  change, wasTooSmall;
  221.  
  222.     DisableInput();
  223.    
  224.     while( traces.total != 0 )
  225.     RemoveTrace( traces.first );
  226.  
  227.  
  228.     if( windowState.iconified )
  229.       {
  230.     EnableInput();
  231.     return;
  232.       }
  233.  
  234.     wasTooSmall = windowState.tooSmall;
  235.  
  236.     change = WindowChanges();
  237.     if( windowState.tooSmall )
  238.       {
  239.     RedrawSmallW();
  240.     EnableInput();
  241.     return;
  242.       }
  243.  
  244.     if( wasTooSmall )
  245.       {
  246.     RedrawBanner();
  247.     RedrawText();
  248.     DrawCursVal( cursorBox );
  249.       }
  250.     RedrawNames( namesBox );
  251.     DrawScrollBar( wasTooSmall );
  252.     RedrawTimes();
  253.     DrawTraces( tims.start, tims.end );
  254.  
  255.     EnableInput();
  256.   }
  257.  
  258.  
  259. private void UpdateWinRemove()
  260.   {
  261.     int  change;
  262.  
  263.     change = WindowChanges();
  264.  
  265.     if( change & RESIZED )
  266.         return;
  267.  
  268.     DisableInput();
  269.  
  270.     if( not (change & NTRACE_CHANGE) )          /* no trace became visible */
  271.         SetSignalPos();
  272.  
  273.     if( change & WIDTH_CHANGE )
  274.       {
  275.         DrawScrollBar( FALSE );
  276.         RedrawTimes();
  277.       }
  278.  
  279.     RedrawNames( namesBox );
  280.     DrawCursVal( cursorBox );
  281.     DrawTraces( tims.start, tims.end );
  282.  
  283.     EnableInput();
  284.   }
  285.  
  286.  
  287. public void RemoveVector( b )
  288.   bptr  b;
  289.   {
  290.     Trptr  t, tmp;
  291.     int    i = FALSE;
  292.  
  293.     for( t = traces.first; t != NULL; )
  294.       {
  295.     if( t->vector and (t->n.vec == b) )
  296.       {
  297.         tmp = t->next;
  298.         RemoveTrace( t );
  299.         t = tmp;
  300.         i = TRUE;
  301.       }
  302.     else
  303.         t = t->next;
  304.       }
  305.     if( i )
  306.     UpdateWinRemove();
  307.   }
  308.  
  309.  
  310.  
  311. public void RemoveNode( n )
  312.   nptr  n;
  313.   {
  314.     Trptr  t, tmp;
  315.     int    i = FALSE;
  316.  
  317.     for( t = traces.first; t != NULL; )
  318.       {
  319.     if( not t->vector and (t->n.nd == n) )
  320.       {
  321.         tmp = t->next;
  322.         RemoveTrace( t );
  323.         t = tmp;
  324.         i = TRUE;
  325.       }
  326.     else
  327.         t = t->next;
  328.       }
  329.     if( i )
  330.     UpdateWinRemove();
  331.   }
  332.  
  333.  
  334. public void RemoveAllDeleted()
  335.   {
  336.     Trptr  t, tmp;
  337.     int    i = FALSE;
  338.  
  339.     for( t = traces.first; t != NULL; )
  340.       {
  341.     if( (t->vector and (t->n.vec->traced & DELETED)) or
  342.       (not t->vector and (t->n.nd->nflags & DELETED)) )
  343.       {
  344.         tmp = t->next;
  345.         RemoveTrace( t );
  346.         t = tmp;
  347.         i = TRUE;
  348.       }
  349.     else
  350.         t = t->next;
  351.       }
  352.     if( i )
  353.     UpdateWinRemove();
  354.   }
  355.  
  356.